// components/navcell/navcell.js
Component({
  properties: {
    caption: {
      type: String,
      value: ''
    },
    icon: {
      type: String,
      value: ''
    },
    target: {
      type: String,
      value: ''
    }
  },
  data: {
    active: {
      type: Boolean,
      value: false
    }
  },
  methods: {
    repaint: function () {
      const pages = getCurrentPages();
      const page = pages[pages.length - 1];
      if (page) {
        const route = page.route;
        const value = this.data.target.indexOf(route) > -1;
        this.setData({
          active: value
        });
      }
    },
    onTap: function () {
      if (!this.data.active) {
        wx.switchTab({
          url: this.data.target
        });
      }
    }
  },
  attached: function () {
    this.setData({
      active: false
    });
  }
})
